package com.yuanian.ecsplus.converter;

import com.yuanian.businessobject.model.entity.base.BOMRefValueBean;
import com.yuanian.ecsplus.context.ReflectContext;
import com.yuanian.ecsplus.exception.EcsPlusException;
import com.yuanian.ecsplus.reflect.SimplePersistenceMetaClass;

/**
 * BOMRefValueBean类型的转换器
 */
public class BOMRefValueBeanTypeConverter extends CommonTypeConverter implements TypeConverter {

    @Override
    public Object obj2Map(ReflectContext reflectContext) {
        if (reflectContext.getObject() == null || reflectContext.getField() == null) {
            throw new EcsPlusException("转换对象为null");
        }
        try {
            BOMRefValueBean bomRefValueBean = (BOMRefValueBean)reflectContext.getRawResult();
            return bomRefValueBean.getValue();
        } catch (IllegalAccessException e) {
            throw new EcsPlusException(e.getCause());
        }
    }

  /*  @Override
    public Object map2Obj(ReflectContext reflectContext) {
        if (reflectContext.getMap() == null || reflectContext.getField() == null) {
            return null;
        }
       *//* if (reflectContext.getMetaClass() instanceof SimplePersistenceMetaClass) {
            SimplePersistenceMetaClass simplePersistenceMetaClass = (SimplePersistenceMetaClass)reflectContext.getMetaClass();
            String fieldName = (String)simplePersistenceMetaClass.getRefMap().get(reflectContext.getField());
            Object result = reflectContext.getMap().get(fieldName);
            return result != null && reflectContext.getField().getType() != result.getClass() ? null : result;
        } else {
            return null;
        }*//*
        //获取MAP对应字段的数据
        Object mapValue = reflectContext.getMapData();
        //类型不兼容
        if (mapValue != null && reflectContext.getField().getType() != mapValue.getClass()) {
            throw new EcsPlusException(reflectContext.getField().getType() + ":" + mapValue.getClass() + "类型不兼容");
        }
        return mapValue;
    }*/

}
